package com.docMan.bean;

import java.util.concurrent.Callable;

import com.docMan.dao.pojo.DocDirectory;
import com.docMan.dao.pojo.DocFtp;
import com.docMan.service.DocDirectoryService;
import com.docMan.service.DocDiscService;
import com.docMan.utils.DeleteFileService;
import com.docMan.utils.FinalConfig;
import com.docMan.utils.FtpUtils;
import com.docMan.utils.GetRealPath;
import com.docMan.utils.SpringContextUtils;


public class FileMoverRunnable implements Callable<Boolean> {
	private DocFtp xtServer2, xtServerFrom;
	private String localPath, remotePath, fileName;
	private int fileMoveType = 0;
	private DeleteFileService deleteFileService=DeleteFileService.getInstance();
	public FileMoverRunnable(DocFtp xtServer2, DocFtp xtServerFrom,
			String pathFrom, String remotePath, String fileName) {
		super();
		this.xtServer2 = xtServer2;
		this.xtServerFrom = xtServerFrom;
		this.localPath = pathFrom;
		this.remotePath = remotePath;
		this.fileName = fileName;
		fileMoveType = 2;
	}

	/**
	 * 
	 * @param xtServer2
	 * @param localPath
	 * @param remotePath
	 */
	public FileMoverRunnable(DocFtp xtServer2, String localPath,
			String remotePath) {
		super();
		this.xtServer2 = xtServer2;
		this.localPath = localPath;
		this.remotePath = remotePath;
		fileMoveType = 1;
	}


	@Override
	public Boolean call() throws Exception {
		try {
			if (fileMoveType == FinalConfig.FILE_MOVE_F2F) {
			} else if (fileMoveType == FinalConfig.FILE_MOVE_L2F) {
				String realPath=GetRealPath.getPath(remotePath);
				if(FtpUtils.movelocalFile2Ftp(xtServer2,
						localPath, realPath)){
					//TODO 先为可索引的文件建立索引，然后将成功上传到ftp的本地文件删除
//					deleteFileService.deleteFile(localPath);
					return true;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		return false;
	}
}
